﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MyImaginaryFriends_Redux
{
    class InputHandler
    {
        KeyboardState KBState;
        KeyboardState PrevKBState;

        GamePadState GPState;
        GamePadState PrevGPState;

        /// <summary>
        /// constructor. This will also act as an initialize function.
        /// </summary>
        public InputHandler()
        {
            KBState = new KeyboardState();
            GPState = new GamePadState();
        }

        public void Update()
        {
            PrevKBState = KBState;
            PrevGPState = GPState;

            KBState = Keyboard.GetState();
            GPState = GamePad.GetState(PlayerIndex.One);
        }

        public bool GetKBState(Keys key)
        {
            if (KBState.IsKeyDown(key))
                return true;
            else return false;
        }

        public bool GetKBStateReleased(Keys key)
        {
            if(KBState.IsKeyUp(key))
                return true;
            else return false;
        }

        public bool GetKBStateSingle(Keys key)
        {
            if(KBState.IsKeyDown(key) && PrevKBState.IsKeyUp(key))
                return true;
            else return false;
        }

        public bool GetKBStateHeld(Keys key)
        {
            if (KBState.IsKeyDown(key) && PrevKBState.IsKeyDown(key))
                return true;
            else return false;
        }

        //Do the GamePadState get for the game pad after we add the game pad functionality.
        public bool GetGPState(Buttons buttons)
        {
            if (GPState.IsButtonDown(buttons))
                return true;
            else return false;
        }

        public bool GetGPStateReleased(Buttons button)
        {
            if (GPState.IsButtonUp(button))
                return true;
            else return false;
        }

        public bool GetGPStateSingle(Buttons button)
        {
            if (GPState.IsButtonDown(button) && PrevGPState.IsButtonUp(button))
                return true;
            else return false;
        }

        public bool GetGPStateHeld(Buttons button)
        {
            if (GPState.IsButtonDown(button) && PrevGPState.IsButtonDown(button))
                return true;
            else return false;
        }
    }
}
